package com.zc.operator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.BaseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.operator.domain.ChargeStation;
import com.zc.operator.service.IChargeStationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 场站Controller
 *
 * @author glb
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/operator/station")
public class ChargeStationController extends BaseController
{
    @Autowired
    private IChargeStationService chargeStationService;

    /**
     * 查询场站列表
     */
    @PreAuthorize("@ss.hasPermi('operator:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeStation chargeStation)
    {
        startPage();
        List<ChargeStation> list = chargeStationService.selectChargeStationList(chargeStation);
        return getDataTable(list);
    }

    /**
     * 导出场站列表
     */
    @PreAuthorize("@ss.hasPermi('operator:station:export')")
    @Log(title = "场站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeStation chargeStation)
    {
        List<ChargeStation> list = chargeStationService.selectChargeStationList(chargeStation);
        ExcelUtil<ChargeStation> util = new ExcelUtil<>(ChargeStation.class);
        util.exportExcel(response, list, "场站数据");
    }

    /**
     * 获取场站详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:station:query')")
    @GetMapping(value = "/{chargeStationId}")
    public AjaxResult getInfo(@PathVariable("chargeStationId") Long chargeStationId)
    {
        return AjaxResult.success(chargeStationService.selectChargeStationByChargeStationId(chargeStationId));
    }

    /**
     * 新增场站
     */
    @PreAuthorize("@ss.hasPermi('operator:station:add')")
    @Log(title = "场站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeStation chargeStation)
    {
        return toAjax(chargeStationService.insertChargeStation(chargeStation));
    }

    /**
     * 修改场站
     */
    @PreAuthorize("@ss.hasPermi('operator:station:edit')")
    @Log(title = "场站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeStation chargeStation)
    {
        return toAjax(chargeStationService.updateChargeStation(chargeStation));
    }

    /**
     * 删除场站
     */
    @PreAuthorize("@ss.hasPermi('operator:station:remove')")
    @Log(title = "场站", businessType = BusinessType.DELETE)
    @DeleteMapping("/{chargeStationIds}")
    public AjaxResult remove(@PathVariable Long[] chargeStationIds)
    {
        return toAjax(chargeStationService.deleteChargeStationByChargeStationIds(chargeStationIds));
    }

    /**
     * 获取状态统计
     */
    @PreAuthorize("@ss.hasPermi('operator:station:list')")
    @GetMapping("/getStatus")
    public AjaxResult getStatus(BaseEntity entity)
    {
        return AjaxResult.success(chargeStationService.getStatus(entity));
    }
}
